@using BootstrapBlazor.Components

<Modal @ref="SmallModal">
    <ModalDialog Size="Size.Medium" ShowResize="true" Title="个人中心" ShowCloseButton="false" Style="width: 355px;">
        <BodyTemplate>
            <div class="personal-center">
                <div class="user-info mb-4">
                    <div class="text-center">
                        <i class="fa-solid fa-user-circle fa-3x text-primary mb-2"></i>
                        <h5>@CurrentUserDisplayName</h5>
                        <p class="text-muted">@CurrentUserName</p>
                    </div>
                </div>
                
                <div class="password-change-section">
                    <h6 class="border-bottom pb-2">修改密码</h6>
                    
                   
                    @* @if (!string.IsNullOrEmpty(PasswordErrorMessage))
                    {
                        <div class="alert alert-danger" role="alert">
                            <i class="fa-solid fa-exclamation-triangle me-2"></i>@PasswordErrorMessage
                        </div>
                    }
                    
                    @if (!string.IsNullOrEmpty(PasswordSuccessMessage))
                    {
                        <div class="alert alert-success" role="alert">
                            <i class="fa-solid fa-check-circle me-2"></i>@PasswordSuccessMessage
                        </div>
                    } *@
                    
                    <div class="form-group mb-3">
                        @* <label for="currentPassword" class="form-label">当前密码</label> *@
                        <div class="input-group">
                            <InputText id="currentPassword" type="password" class="@GetCurrentPasswordClass()" @bind-Value="CurrentPassword" placeholder="请输入当前密码" @onblur="ValidateCurrentPassword" />
                            @if (!string.IsNullOrEmpty(CurrentPassword))
                            {
                                <button class="btn btn-outline-secondary" type="button" @onclick="ClearCurrentPassword">
                                    <i class="fa-solid fa-times"></i>
                                </button>
                            }
                        </div>
                        @if (IsCurrentPasswordError)
                        {
                            <div class="invalid-feedback">当前密码不能为空或密码错误</div>
                        }
                    </div>
                    
                    <div class="form-group mb-3">
                        @* <label for="newPassword" class="form-label">新密码</label> *@
                        <div class="input-group">
                            <InputText id="newPassword" type="password" class="@GetNewPasswordClass()" @bind-Value="NewPassword" placeholder="请输入新密码（至少6位）" @onblur="ValidateNewPassword" />
                            @if (!string.IsNullOrEmpty(NewPassword))
                            {
                                <button class="btn btn-outline-secondary" type="button" @onclick="ClearNewPassword">
                                    <i class="fa-solid fa-times"></i>
                                </button>
                            }
                        </div>
                        @if (IsNewPasswordError)
                        {
                            <div class="invalid-feedback">新密码不能为空且长度不能少于6位</div>
                        }
                    </div>
                    
                    <div class="form-group mb-3">
                        @* <label for="confirmPassword" class="form-label">确认新密码</label> *@
                        <div class="input-group">
                            <input id="confirmPassword" type="password" class="@GetConfirmPasswordClass()" value="@ConfirmPassword" @oninput="OnConfirmPasswordInput" @onkeyup="ValidateConfirmPasswordRealTime" @onblur="ValidateConfirmPassword" placeholder="请再次输入新密码" />
                            @if (!string.IsNullOrEmpty(ConfirmPassword))
                            {
                                <button class="btn btn-outline-secondary" type="button" @onclick="ClearConfirmPassword">
                                    <i class="fa-solid fa-times"></i>
                                </button>
                            }
                        </div>
                        @if (IsConfirmPasswordError)
                        {
                            <div class="invalid-feedback">确认密码不能为空且必须与新密码一致</div>
                        }
                    </div>
                </div>
            </div>
        </BodyTemplate>
        <FooterTemplate>
            <div class="d-grid">
                <button class="btn @GetButtonClass()" @onclick="ChangePasswordAsync" disabled="@IsChangingPassword">
                    <i class="@GetButtonIcon() me-2"></i>@GetButtonText()
                </button>
            </div>
        </FooterTemplate>
    </ModalDialog>
</Modal>

@code {
    private Modal? SmallModal { get; set; }
    
    // 打开模态框方法
    public async Task ShowAsync()
    {
        ResetForm();
        if (SmallModal != null)
        {
            LogWrapper.Information("访问个人中心");
            await SmallModal.Toggle();
        }
    }
    
    // 关闭模态框方法
    public async Task HideAsync()
    {
        if (SmallModal != null)
        {
            await SmallModal.Toggle();
        }
    }
}